"""
商户服务模块
"""

from jlpay.services.base_service import BaseService
from jlpay.model.openmerch.register.merchant import (
    MerchantIncomingAddRequest, MerchantIncomingAddResponse,
    MerchantIncomingModifyRequest, MerchantIncomingModifyResponse,
    RealnameQueryRequest, RealnameQueryResponse,
    MerchantOrderQueryRequest, MerchantOrderQueryResponse,
    MerchantOrderCancelRequest, MerchantOrderCancelResponse
)

class MerchantService(BaseService):
    """商户服务类"""
    
    def __init__(self, config):
        """
        初始化商户服务
        
        Args:
            config: OrgConfig实例
        """
        super().__init__(config)
    
    def get_api_url(self, request_class, api_path=None):
        """
        获取API URL
        
        Args:
            request_class: 请求类
            api_path: 接口路径
            
        Returns:
            完整的API URL
        """
        base_url = self.config.url
        
        if api_path:
            return f"{base_url}{api_path}"
        
        # 直接使用Request类中定义的完整API路径
        api_url = getattr(request_class, 'API_URL', '')
        
        if not api_url:
            # 如果没有定义API_URL，使用默认路径
            return f"{base_url}/open/merch/access"
        
        # 直接返回完整路径
        return f"{base_url}{api_url}"
    
    def merchant_incoming_add(self, request):
        """
        商户进件接口
        
        Args:
            request: MerchantIncomingAddRequest实例
            
        Returns:
            MerchantIncomingAddResponse实例
        """
        return self.post(request, MerchantIncomingAddResponse)
    
    def merchant_incoming_modify(self, request):
        """
        进件修改接口
        
        Args:
            request: MerchantIncomingModifyRequest实例
            
        Returns:
            MerchantIncomingModifyResponse实例
        """
        return self.post(request, MerchantIncomingModifyResponse)
    
    def realname_query(self, request):
        """
        微信支付宝认证查询接口
        
        Args:
            request: RealnameQueryRequest实例
            
        Returns:
            RealnameQueryResponse实例
        """
        return self.post(request, RealnameQueryResponse)
        
    def merchant_order_query(self, request):
        """
        商户申请单查询接口
        
        Args:
            request: MerchantOrderQueryRequest实例
            
        Returns:
            MerchantOrderQueryResponse实例
        """
        return self.post(request, MerchantOrderQueryResponse)
    
    def merchant_order_cancel(self, request):
        """
        商户申请单作废接口
        
        Args:
            request: MerchantOrderCancelRequest实例
            
        Returns:
            MerchantOrderCancelResponse实例
        """
        return self.post(request, MerchantOrderCancelResponse) 